
const nodemailer = require("nodemailer");

// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
    host: "smtp.qq.com",
    port: 465,
    secure: true, // true for 465, false for other ports
    auth: {
        user: 'lx_tyin@qq.com', // generated ethereal user
        pass: 'fatfczhzqeqpfcig', // generated ethereal password
    },
});

async function send_email(target, subject, content) {
    // send mail with defined transport object
    let info = await transporter.sendMail({
        from: '来自 <lx_tyin@qq.com>',
        to: target,
        subject: subject,
        text: content,
    });

    console.log("Message sent: %s", info.messageId);
    // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>

    // Preview only available when sending through an Ethereal account
    console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
    // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}

exports.send_email = send_email;
